package com.winit.schedule.task.tracker.schema;

import java.util.Set;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

import com.winit.schedule.core.task.annotation.ScheduleTask;

public class UScheduleAnnotationParser implements BeanDefinitionParser {

    private static final String BASE_PACKAGE_ATTRIBUTE = "package";

    @Override
    public BeanDefinition parse(Element element, ParserContext parserContext) {
        String[] basePackages = StringUtils.tokenizeToStringArray(element.getAttribute(BASE_PACKAGE_ATTRIBUTE),
            ",",
            true,
            true);

        UScheduleClassPathBeanDefinitionScanner scanner = new UScheduleClassPathBeanDefinitionScanner(parserContext.getRegistry(),
            true);
        AnnotationTypeFilter AnnotationTypeFilter = new AnnotationTypeFilter(ScheduleTask.class);
        scanner.addIncludeFilter(AnnotationTypeFilter);

        @SuppressWarnings("unused")
        Set<BeanDefinitionHolder> beanDefinitions = scanner.doScan(basePackages);

        return null;
    }

}
